package com.lovo.manage.controller;

import com.lovo.manage.bean.Pagination;
import com.lovo.manage.bean.Student;
import com.lovo.manage.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping("")
    public Pagination find(@RequestParam(defaultValue="1")int page, @RequestParam(defaultValue="5")int rows){
        return studentService.find(page,rows);
    }

    @GetMapping("/{id}")
    public Student findById(@PathVariable("id") int id){
        return studentService.findById(id);
    }

    @PostMapping("")
    public String add(Student student){
        studentService.addStudent(student);
        return "suc";
    }

    @PutMapping("/{id}")
    public String update(@PathVariable("id") int id,Student student){
        student.set_id(id);
        studentService.updateStudent(student);
        return "suc";
    }

    @DeleteMapping("/{id}")
    public String del(@PathVariable("id") int id){
        studentService.delStudent(id);
        return "suc";
    }

}
